<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of alipay
 *
 * @author yuankai
 */
class Controller_Pay extends Controller implements Controller_Alipay {

    /**
     * 支付首页，测试用
     */
    public function action_index() {
        $this->request->response = View::factory('pay/index');
    }

    /**
     * 显示跳转表单页面
     */
    public function action_dopay() {

        //必填参数
        $out_trade_no = date(Ymdhms);    //请与贵网站订单系统中的唯一订单号匹配
        $subject = $_POST['aliorder'];  //订单名称，显示在支付宝收银台里的“商品名称”里，显示在支付宝的交易管理的“商品名称”的列表里。
        $body = $_POST['alibody'];  //订单描述、订单详细、订单备注，显示在支付宝收银台里的“商品描述”里
        $price = $_POST['alimoney'];  //订单总金额，显示在支付宝收银台里的“应付总额”里
        //构造要请求的参数数组
        $parameter = array(
            //从订单数据中动态获取到的必填参数
            "out_trade_no" => $out_trade_no,
            "subject" => $subject,
            "body" => $body,
            "price" => $price,
            "quantity" => 1,
            "logistics_fee" => '0.00',
            "logistics_type" => 'EXPRESS',
            "logistics_payment" => 'SELLER_PAY'
        );

        $form_html = Alipay::service('escrow', $parameter)
                        ->build_form('POST', FALSE);

        $this->request->response = $form_html;
    }

    /**
     * 接受支付宝订单变更通知
     */
    public function action_notify() {

    }

    /**
     * 用户支付完毕返回的地址
     */
    public function action_return() {
        $verfiy_result = Pay::instance('alipay')->return_verify();
        $this->request->response = View::factory('pay/return');
    }

}

?>
